<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>首页</title>
    <script src="js/jquery.min.js"></script>
</head>
<body>
    <input id="click" type="button" value="点击" onclick="operate('click')" />
    <input id="collect" type="button" value="收藏" onclick="operate('job_collect')" />
    <input id="send" type="button" value="投简历" onclick="operate('cv_send')" />
    <input id="upload" type="button" value="上传简历" onclick="operate('cv_upload')" />
</body>
<script>

    function operate(action) {
        // 构建kafka需要的参数数据
        let user_id = 'user_test_' + Math.ceil(Math.random() * 10);
        let job_code = 'job_code' + Math.ceil(Math.random() * 10);
        let action_time = currentStrTime();
        let json = {
            'user_id': user_id,
            'act_time': action_time,
            'action': action,
            'job_code': job_code
        };

        $.ajax({
            url:"http://www.test.com/kafka/log",
            type:"POST" ,
            crossDomain: true,
            data: JSON.stringify(json),
            // 开启跨域访问
            //xhrFields: {
            //    withCredentials: true
            //},
            success:function (result, status, xhr) {
                // console.log("操作" + action +" + 成功, 且记录日志结果为：'" + result)
                console.log("操作" + action +" + 成功, 且记录日志成功：'")
            },
            error:function (result) {
                // console.log("操作" + action +" + 失败, 且记录日志结果为：'" + result)
            }
        });
    };

    /**
     * 创建当前时间
     * @returns {string} 时间字符串
     */
    function currentStrTime() {
        let date   = new Date();
        let str = '';
        str += date.getFullYear() + '-';
        str += date.getMonth() + 1 + '-';
        str += date.getDate() + ' ';
        str += date.getHours() + ':';
        str += date.getMinutes() + ':';
        str += date.getSeconds();
        return str.toString();
    }
</script>
</html>
